Skip to content

feat(research): add Phase 11 BREADTH cross-asset and futures screening gate - #819

Merged
Pigbibi merged 1 commit into
mainfrom
feat/breadth-cross-asset-screening
Nov 27, 2026
Merged

Pigbibi merged 1 commit into
mainfrom
feat/breadth-cross-asset-screening

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

AI assistance

Antigravity AI assistant (gemini-3.1-pro)

What changed

  • Add src/quant_platform_kit/research_stats/breadth_screening.py implementing the Phase 11 BREADTH offline cross-asset and futures screening evaluator:
    • Defines BREADTH_ASSET_CLASSES, BreadthDatasetManifest, BreadthScreeningResult, and evaluate_breadth_candidate(...).
    • Fails closed on invalid/missing manifest fields, unverified point-in-time status, invalid SHA-256 dataset digests, leverage exceeding max_leverage_allowed, or futures datasets missing a roll_rule or explicit margin_isolated_from_cash_buffer=True.
    • Composes lower_tail_correlation_gate(...) (< 0.50 point + stationary-bootstrap UCB) and deflated_sharpe_ratio(...) (>= min_dsr) into a single research-only screening verdict.
  • Export the new symbols from quant_platform_kit.research_stats.
  • Add unit tests in tests/test_research_stats_breadth_screening.py.

How verified

  • git diff --check passed.
  • .venv/bin/python -m pytest -q tests/test_research_stats_breadth_screening.py tests/test_research_stats_tail_correlation.py tests/test_research_stats_import_boundary.py tests/test_architecture_boundaries.py -> 30 passed in 20.21s.
  • .venv/bin/ruff check -> All checks passed!.
  • .venv/bin/pyright -> 0 errors, 0 warnings, 0 informations.

Why

Provides a single deterministic, fail-closed offline screening helper for Phase 11 BREADTH cross-asset (gold, treasury, non-US equity, commodity, FX) and isolated CTA futures sleeves, including explicit futures cash-buffer isolation and continuous roll checks.

Risk

  • Tier: standard research-only statistics (src/quant_platform_kit/research_stats/ + tests/).
  • Impact: Pure offline research helper; no broker, account, runtime, or deployed service changes.

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The new breadth_screening module is a research-only, fail-closed helper that composes existing tail-correlation and DSR gates. The implementation is mostly sound, but there are a few correctness and robustness concerns: (1) the trial_count extraction only accepts int from details['n_effective_trials'], silently dropping a valid count if the underlying helper records it as a float or numpy integer, and it is never validated against n_effective_trials; (2) evaluate_breadth_candidate consumes candidate_returns/benchmark_returns/trial_sharpes as Iterable but passes them to two downstream helpers sequentially, so a one-shot generator would be exhausted by the first call and silently produce wrong results; (3) the overall_status computation is convoluted and duplicates the failed list logic, and passes_gate can be True while status is STATUS_UNCOMPUTABLE only if downstream helpers misbehave, but the invariant is not asserted; (4) _validate_manifest catches ResearchInputError from finite_float and maps it to excess_leverage, conflating non-finite leverage with excess leverage and losing diagnostic detail; (5) tests do not cover the generator/iterator input path, the n_effective_trials override path, or the trial_count field value, leaving the silent-drop bug untested. No security, secret, or architecture-boundary violations were found; the module stays within research_stats and does not touch runtime/broker code.

Reviewed commit: 1c37d30be3 · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] src/quant_platform_kit/research_stats/breadth_screening.py: candidate_returns, benchmark_returns, and trial_sharpes are typed as Iterable but are consumed by two downstream helpers (lower_tail_correlation_gate and deflated_sharpe_ratio). If a caller passes a one-shot generator/iterator, the second consumer sees an exhausted iterable and silently produces wrong (likely uncomputable or degenerate) results instead of raising. Materialize inputs to tuples/lists at the top of the function, or narrow the type to Sequence.
  • [MEDIUM] src/quant_platform_kit/research_stats/breadth_screening.py: trial_count is derived via isinstance(recorded_trials, int), which silently drops a valid count if deflated_sharpe_ratio records n_effective_trials as a float or numpy integer. The result then reports trial_count=None even though a count exists, and the value is never cross-checked against the caller-supplied n_effective_trials. Use a tolerant numeric coercion (e.g. int(recorded_trials) guarded by isinstance(..., (int, float)) and finiteness) and assert consistency with the override when provided.
  • [LOW] src/quant_platform_kit/research_stats/breadth_screening.py: _validate_manifest maps any ResearchInputError from finite_float (e.g. NaN/inf leverage) to excess_leverage, conflating non-finite input with an actual leverage breach and losing diagnostic detail. Consider a distinct invalid_leverage gate or include the underlying reason.
  • [LOW] src/quant_platform_kit/research_stats/breadth_screening.py: overall_status recomputes the same conditions already reflected in failed and is hard to read; passes_gate and status can in principle disagree (passes_gate True with STATUS_UNCOMPUTABLE) if a downstream helper changes. Derive status from failed/passes_gate directly and add an invariant assertion.
  • [LOW] tests/test_research_stats_breadth_screening.py: Tests do not cover: (a) generator/iterator inputs to evaluate_breadth_candidate (the exhaustion bug above), (b) the n_effective_trials override path, (c) the value of trial_count in the result, or (d) min_dsr boundary values (0.0, 1.0). Add cases for these to lock in the fail-closed contract.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T19:07:42.842780Z 409eb56 Manual request
🔒 Security Review ✅ Completed 2026-11-27T19:09:36.280696Z 409eb56 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c37d30be3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Pigbibi
Pigbibi force-pushed the feat/breadth-cross-asset-screening branch from 1c37d30 to 409eb56 Compare November 27, 2026 19:06
@Pigbibi

Pigbibi commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The PR adds a research-only breadth screening module with fail-closed manifest validation and composes existing tail-correlation and DSR gates. The implementation is generally sound, but there are a few correctness and robustness concerns: the _materialize_series helper silently swallows TypeError and returns the original iterable, which can cause downstream gates to consume a generator twice or fail confusingly; the trial_count extraction relies on a loosely-typed details dict and silently yields None on unexpected shapes; and the uncomputable_gates set treats invalid_min_dsr as uncomputable rather than a validation failure, which conflates input errors with data errors. Tests cover the main paths but do not exercise the _materialize_series TypeError fallback or the case where deflated_sharpe_ratio returns a non-integer n_effective_trials.

Reviewed commit: 409eb56e45 · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] src/quant_platform_kit/research_stats/breadth_screening.py: _materialize_series catches TypeError and returns the original iterable unchanged. If a caller passes a one-shot generator that raises TypeError during iteration (e.g. a generator that itself raises), the same generator is then passed to both lower_tail_correlation_gate and deflated_sharpe_ratio, so the second consumer sees an exhausted iterator and silently produces an uncomputable result instead of surfacing the real error. Prefer letting the TypeError propagate or converting to a list with an explicit error.
  • [MEDIUM] src/quant_platform_kit/research_stats/breadth_screening.py: trial_count is derived from dsr_result.details.get("n_effective_trials") with a permissive isinstance/isfinite/is_integer check that silently yields None on any unexpected shape. This is silent error swallowing: if the DSR implementation changes its details key or returns a float like 2.9999999, the screening result reports trial_count=None without any failure gate, so downstream consumers cannot distinguish 'no trials' from 'shape mismatch'. Either validate strictly and add a failure gate, or document the contract.
  • [LOW] src/quant_platform_kit/research_stats/breadth_screening.py: invalid_min_dsr is included in uncomputable_gates, so a caller-supplied invalid threshold (e.g. 0.0, 1.0, NaN) is reported as STATUS_UNCOMPUTABLE rather than a validation/input error. This conflates bad caller input with uncomputable data and makes the status less informative. Consider a distinct status or at least keep it out of the uncomputable set so passes_gate=False with STATUS_COMPUTED reflects a validation failure.
  • [LOW] tests/test_research_stats_breadth_screening.py: Tests do not cover the _materialize_series TypeError fallback path, nor the case where deflated_sharpe_ratio returns a non-integer or missing n_effective_trials in details. Add a test that exercises a generator raising TypeError and a test asserting trial_count behavior when details shape is unexpected, to lock in the intended contract.
  • [LOW] src/quant_platform_kit/research_stats/breadth_screening.py: _materialize_series returns object and callers use # type: ignore[arg-type] to pass it into typed gate functions. This defeats type checking at the boundary; prefer returning tuple[object, ...] | str | bytes or a dedicated union type so the ignores can be removed and pyright actually validates the call sites.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 409eb56e45

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 409eb56e45

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Pigbibi
Pigbibi merged commit 41347fa into main Nov 27, 2026
12 of 13 checks passed
@Pigbibi
Pigbibi deleted the feat/breadth-cross-asset-screening branch November 27, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant